package cn.silver.framework.satoken.model;

import cn.silver.framework.core.utils.DateUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

/**
 * 当前在线会话
 *
 * @author ruoyi
 */

@Data
@Schema(name = "OnlineModel", title = "在线用户对象")
@NoArgsConstructor
public class OnlineModel implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;
    /**
     * 用户主键
     */
    @Schema(title = "用户主键")
    private String id;
    /**
     * 用户名称
     */
    @Schema(title = "登录用户编号")
    private String userCode;
    /**
     * 用户名称
     */
    @Schema(title = "登录用户姓名")
    private String userName;

    @Schema(title = "登录租户")
    private String tenantCode;

    @Schema(title = "认证方式")
    private String authType;

    @Schema(title = "设备类型")
    private String deviceType;
    /**
     * 会话编号
     */
    @Schema(title = "登录会话编码")
    private String tokenId;

    /**
     * 部门名称
     */
    @Schema(title = "所属组织")
    private String deptName;
    /**
     * 登录IP地址
     */
    @Schema(title = "登录IP")
    private String ipaddr;

    /**
     * 登录地址
     */
    @Schema(title = "登录地点")
    private String address;

    /**
     * 浏览器类型
     */
    @Schema(title = "登录客户端")
    private String browser;

    /**
     * 操作系统
     */
    @Schema(title = "客户端系统")
    private String os;
    /**
     * 登录时间
     */
    @Schema(title = "登录时间")
    @JsonFormat(timezone = DateUtils.TIME_ZONE, pattern = DateUtils.YYYY_MM_DD_HH_MM_SS)
    private Date loginTime;

    public OnlineModel(LoginUser loginUser) {
        this.id = loginUser.getId();
        this.userCode = loginUser.getCode();
        this.userName = loginUser.getName();
        this.tenantCode = loginUser.getTenantId();
        this.deptName = loginUser.getDeptName();
        this.deviceType = loginUser.getDeviceType();
        this.authType = loginUser.getAuthType();
    }
}
